import request from '@/config/axios'
import service from '@/config/axios/service'

// 获取config配置
export const getConfig = (): Promise<IResponse<any>> => {
  return service({ url: '/api/basic/get_configs', method: 'get' })
}

export const verifyLicense = (data?: any): Promise<IResponse<any>> => {
  return request.post({ url: '/api/user/verify_license_client', data })
}

// 获取表格配置
export const getTableMeta = (data: any): Promise<IResponse<any>> => {
  return request.post({ url: '/api/table/meta', data })
}

// 获取表格数据
export const getTableList = (data: any): Promise<IResponse<any>> => {
  return request.post({ url: '/api/table/search', data })
}

// 获取单条数据
export const getTableItem = (data: any): Promise<any> => {
  return request.post({ url: '/api/basic/table/item', data })
}

// 新增表格数据
export const addTableData = (data: any): Promise<IResponse<any>> => {
  return request.post({ url: '/api/table/add', data })
}

// 编辑表格数据
export const editTableData = (data: any): Promise<IResponse<any>> => {
  return request.post({ url: '/api/table/edit', data })
}

// 删除表格数据
export const deleteTableData = (data: any): Promise<IResponse<any>> => {
  return request.post({ url: '/api/table/delete', data })
}

// 导出表格数据
export const exportTableData = (data: any): Promise<IResponse<any>> => {
  return request.post({ url: '/api/table/search_export', data })
}

// 通用操作
export const generalOperation = (data: any): Promise<IResponse<any>> => {
  return request.post({ url: '/api/table/general_operation', data })
}

// 通用Generator
export const doGenerator = (data: any): Promise<IResponse<any>> => {
  return request.post({ url: '/api/generator/general_operation', data })
}

// 获取form下拉框数据
export const getFormValues = (data: any): Promise<IResponse<any>> => {
  return request.post({ url: '/api/form/get_values', data })
}

// 执行api
export const doApi = (url: string, data: any, method = 'get', headers?: any): Promise<any> => {
  return service.request({
    url,
    method,
    data,
    params: method === 'get' ? data : undefined,
    headers
  })
}

// 根据id获取数据
export const getForeignValues = (data: any): Promise<any> => {
  return request.post({
    url: '/api/form/getForeignValues',
    data
  })
}

// 执行api导出文件
export const doAjaxDownload = (
  url: string,
  data: any,
  method = 'get',
  headers?: any
): Promise<any> => {
  return request.post({
    url: url,
    method,
    data,
    params: method === 'get' ? data : undefined,
    headers,
    responseType: 'blob'
  })
}

export const getOrderStatus = (orderId: number): Promise<IResponse<any>> => {
  return request.get({ url: `/api/sng/get_order_info?order_ids=${orderId}` })
}

// 提交审批
export const auditTableData = (data: any): Promise<any> => {
  return request.post({ url: '/api/basic/table/audit', data })
}

// 执行审批
export const approveTableData = (data: any): Promise<any> => {
  return request.post({ url: '/api/basic/table/approve', data })
}

// 批量提交审批（关联表）
export const auditAllTableData = (data: any): Promise<any> => {
  return request.post({ url: '/api/basic/table/auditAll', data })
}

// 批量执行审批（关联表）
export const approveFlowTableData = (data: any): Promise<any> => {
  return request.post({ url: '/api/basic/table/approveFlow', data })
}

// 获取邀请用户信息
export const getInvitedUserInfo = (data: any): Promise<IResponse<any>> => {
  return request.post({ url: '/api/invited_users/info', data })
}

// 获取用户订单
export const getUserOrders = (data: any): Promise<IResponse<any>> => {
  return request.post({ url: '/api/user/orders', data })
}

// 获取用户信息
export const getUserInfo = (): Promise<IResponse<any>> => {
  return request.get({ url: '/api/user/info' })
}
